package com.site.util.common;

/**
 * Purpose: md5加密
 * @author: liangjun
 * @since: JDK 1.6
 * @date: 2015年9月21日
 */
public class MD5Util {
	
	public static String MD5(String strTemp) throws Exception {
		java.security.MessageDigest mdAlgorithm = java.security.MessageDigest.getInstance("MD5");
		mdAlgorithm.update(strTemp.getBytes());

		byte[] digest = mdAlgorithm.digest();
		StringBuffer hexString = new StringBuffer();

		for (int i = 0; i < digest.length; i++) {
			strTemp = Integer.toHexString(0xFF & digest[i]);

		    if (strTemp.length() < 2) {
		    	strTemp = "0" + strTemp;
		    }

		    hexString.append(strTemp);
		}
		return hexString.toString();
	}
	
}
